package com.nullpointer.remotepaint;

import java.io.PrintWriter;
import java.net.Socket;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;

public class PaintView extends View{

	float x=0,y=0;
	Paint p;
	
	PrintWriter pw;
	private Socket socket;
	
	public PaintView(Context context,PrintWriter pwriter) {
		super(context);
		p=new Paint();
		p.setAntiAlias(true);
		p.setColor(Color.RED);
	    pw=pwriter;
		Log.d("Kiran ","In paint view constructor "+context);

       
		
		// TODO Auto-generated constructor stub
	}
	
	@Override
	public boolean onTouchEvent(MotionEvent e) {
		// TODO Auto-generated method stub
		Log.d("Kiran ","In Paint view on touch ");  
		if(e.getAction()==MotionEvent.ACTION_DOWN){
		x=e.getX();
		y=e.getY();
		
		postInvalidate();
		Log.d("Kiran ","Action Down "+e.getAction());
		}
		
		if(e.getAction()==MotionEvent.ACTION_MOVE){
			x=e.getX();
			y=e.getY();
			
			postInvalidate();
		}
		if(e.getAction()==MotionEvent.ACTION_UP){
			x=e.getX();
			y=e.getY();
			
		 postInvalidate();
		}
		//if(MotionEvent.)
		return true;
	}
	
	
	@Override
	protected void onDraw(Canvas canvas) {
		// TODO Auto-generated method stub 
		super.onDraw(canvas);
		canvas.drawCircle(x, y, 15, p);
		
		Log.d("AMOL", "PrintWriter "+pw);
        String str=""+x+":"+y;  
		
       pw.write(str+"\n");
       pw.flush();
		
		
		}
		
	
  
	
	
		
	
	
	
	

}
